Skip to content

refactor: make block processing async inside PendingBlocks #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 8, 2024

Conversation

mpaulucci
Copy link
Collaborator

Motivation
Before this change, PendingBlocks was waiting for ForkChoice to process the block before updating it's status. This sometimes results in a timeout if there are many blocks that need to be processed, causing the PendingBlocks genserver to crash.

Description

  • Refactored PendingBlocks state to store a map of blocks with it's corresponding status, instead of having one map per status.
  • Adapt PendingBlocks to the fact that all calls to ForkChoice must be async

@mpaulucci mpaulucci requested a review from a team as a code owner February 5, 2024 17:25
@mpaulucci mpaulucci mentioned this pull request Feb 6, 2024
@@ -1,40 +0,0 @@
defmodule Unit.PendingBlocks do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

# If parent is not in fork choice, download parent
not ForkChoice.has_block?(parent_root) ->
state |> Map.update!(:blocks_to_download, &MapSet.put(&1, parent_root))
!Blocks.get_block(parent_root) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a bug: if the parent is in the DB this would be false, and we'd try to process the block even if its parent wasn't processed, causing it to fail and marking it as an invalid block

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this assumes that a block is stored in the DB only if it is processed (and valid). We should not store invalid (or potentially invalid) blocks.

Do we store blocks before processing them today?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. But this can happen if the node restarts after processing some blocks

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is probably out of scope from this PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure. We could patch it up by just nuking the database in the makefile to avoid this error when debugging, but we need to find a better way to handle this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like me to add this to the PR?

Copy link
Collaborator

@Arkenan Arkenan Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a more complex discussion outside of the scope of the PR, which is supporting recoverability, which we don't yet. To do so, we should save the state of a block in the DB.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, I meant we need to find a better way to handle this in a following PR. For now, we can just go for the nuclear option.

Arkenan
Arkenan previously approved these changes Feb 7, 2024
Copy link
Collaborator

@Arkenan Arkenan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left some nit comments.

@mpaulucci mpaulucci merged commit 98acdd8 into main Feb 8, 2024
@mpaulucci mpaulucci deleted the refactor-pending-blocks branch February 8, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants